/*!
 * \file frdb_title_value_chg.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include <frdb_cursor.h>

#include "apmtest_comm.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}


static void __case1(void)
{
    int i_ret = 0;
    char *p_org_title = (char *)frstrdup((char *)"fun(null,123,null)");
    char *p_result_title = NULL;

    i_ret = frdb_title_value_chg(p_org_title, '*', &p_result_title);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_STRING_EQUAL(p_result_title, "FUN(NULL,*,NULL)");

    frfree(p_org_title);
    frfree(p_result_title);

    return;
}

static void __case2(void)
{
    int i_ret = 0;
    char *p_org_title = (char *)frstrdup((char *)"fun(null,   123,null)");
    char *p_result_title = NULL;

    i_ret = frdb_title_value_chg(p_org_title, '*', &p_result_title);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_STRING_EQUAL(p_result_title, "FUN(NULL, *,NULL)");

    frfree(p_org_title);
    frfree(p_result_title);

    return;
}


static void __case3(void)
{
    int i_ret = 0;
    char *p_org_title = (char *)frstrdup((char *)"fun(  100  )");
    char *p_result_title = NULL;

    i_ret = frdb_title_value_chg(p_org_title, '*', &p_result_title);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_STRING_EQUAL(p_result_title, "FUN( * )");

    frfree(p_org_title);
    frfree(p_result_title);

    return;
}

static void __case4(void)
{
    int i_ret = 0;
    char *p_org_title = (char *)frstrdup((char *)"fun(test123.456)");
    char *p_result_title = NULL;

    i_ret = frdb_title_value_chg(p_org_title, '*', &p_result_title);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_STRING_EQUAL(p_result_title, "FUN(TEST123.456)");

    frfree(p_org_title);
    frfree(p_result_title);

    return;
}

static void __case5(void)
{
    int i_ret = 0;
    char *p_org_title = (char *)frstrdup((char *)"value = 123456");
    char *p_result_title = NULL;

    i_ret = frdb_title_value_chg(p_org_title, '*', &p_result_title);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_STRING_EQUAL(p_result_title, "VALUE = *");

    frfree(p_org_title);
    frfree(p_result_title);

    return;
}

static void __case6(void)
{
    int i_ret = 0;
    char *p_org_title = (char *)frstrdup((char *)"value = 'aaa111'");
    char *p_result_title = NULL;

    i_ret = frdb_title_value_chg(p_org_title, '*', &p_result_title);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_STRING_EQUAL(p_result_title, "VALUE = *");

    frfree(p_org_title);
    frfree(p_result_title);

    return;
}

static void __case7(void)
{
    int i_ret = 0;
    char *p_org_title = (char *)frstrdup((char *)"value = 'a\\'aa\\'a'");
    char *p_result_title = NULL;

    i_ret = frdb_title_value_chg(p_org_title, '*', &p_result_title);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_STRING_EQUAL(p_result_title, "VALUE = *");

    frfree(p_org_title);
    frfree(p_result_title);

    return;
}

static void __case8(void)
{
    int i_ret = 0;
    char *p_org_title = (char *)frstrdup((char *)"value = aaa111");
    char *p_result_title = NULL;

    i_ret = frdb_title_value_chg(p_org_title, '*', &p_result_title);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_STRING_EQUAL(p_result_title, "VALUE = AAA111");

    frfree(p_org_title);
    frfree(p_result_title);

    return;
}

int add_suite_frdb_title_value_chg(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frdb_cursor frdb_title_value_chg()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);
    CU_add_test(pSuite, "case4", __case4);
    CU_add_test(pSuite, "case5", __case5);
    CU_add_test(pSuite, "case6", __case6);
    CU_add_test(pSuite, "case7", __case7);
    CU_add_test(pSuite, "case8", __case8);


    return FR_SUCC;
}
